jsx3.Class.defineClass(
        'gix.WindowShadeStaged', // full name of the class to create
        jsx3.gui.Block, //  extends jsx3.lang.Object
        null, // dose not implements any interfaces
        function(windowshade) {  // name the argument of this function "Example"
            /*
             A WindowSahde object contains a 2-D jsx3.gui.LayoutGrid.
             First pane is reserved for the content and the second pain contains a button for scrolling down and up.
            */



            // Create a new logger or returns a pre-existing logger of the same name.
            windowshade.LOGGER = jsx3.util.Logger.getLogger("gix.WindowShadeSatged");
            // Set the level of this Logger.
            windowshade.LOGGER.setLevel(jsx3.util.Logger.ERORR);

            windowshade.prototype._setHeight = function(height) {
                this.height = height;
                this.windowShade.setHeight(height, true);
            }

            windowshade.prototype._setTop = function(top) {
                this._top = top
                this.windowShade.setTop(top, true)
            }

            windowshade.prototype._setDuration = function(duration) {
                this.duration = duration;
            }

            windowshade.prototype._setTimeout = function(timeout) {
                this.timeout = timeout;
            }

            windowshade.prototype._getTop = function() {
                return this._top;
            }

            windowshade.prototype._getDuration = function() {
                return this.duration;
            }


            windowshade.prototype._getTimeout = function() {
                return this.timeout;
            }

            windowshade.DEFAULTTIMEOUT = 50;

            windowshade.DEFAULTDURATION = 500;

            windowshade.DEFAULTDIRECTION = -1

            windowshade.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight) {
                //call constructor for super class
                this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight);
                this.setDuration(windowshade.DEFAULTDURATION);
                this.setTimeout(windowshade.DEFAULTTIMEOUT)
                this.setDirection(windowshade.DEFAULTDIRECTION)
            };


            /**
             *
             * @returns {int}
             */
            windowshade.prototype.getDuration = function() {
                return this.duration;
            };


            /**
             *
             * @param intDuration {int}
             * @returns {jgix.WindowShade} this object
             */
            windowshade.prototype.setDuration = function(intDuration) {
                this.duration = intDuration;
                return this;
            };


            /**
             *
             * @returns {int}
             */
            windowshade.prototype.getTimeout = function() {
                return this.timeout;
            };


            /**
             *
             * @param intDuration {int}
             * @returns {jgix.WindowShade} this object
             */
            windowshade.prototype.setTimeout = function(intTimeout) {
                this.timeout = intTimeout;
                return this;
            };


            windowshade.prototype.getDirection = function() {
                return this.direction;
            }


            windowshade.prototype.setDirection = function(intDirection) {
                this.direction = intDirection;
                return this
            }

            windowshade.prototype.getDistance = function() {
                return this.distance;
            }


            windowshade.prototype.setDistance = function(intDistance) {
                this.distance = intDistance;
                return this
            }


            windowshade.prototype.initializeParameters = function(intDirection, intTimeout, intDuration, windowHeight) {
                try {
                    intDirection = (intDirection)?intDirection: windowshade.DEFAULTDIRECTION
                    this._setDirection = intDirection
                    intTimeout = (intTimeout)?intTimeout: windowshade.DEFAULTTIMEOUT
                    intDuration = (intDuration)?intDuration: windowshade.DEFAULTDURATION

                    // Set the scroll direction to default
                    this.setDirection(intDirection);
                    this.predirection = intDirection

                    this.setTimeout(intTimeout);
                    this.setDuration(intDuration);

                    // Get the parent height
                    var parentHeight = parseInt(this.getParent().getRendered().style.height.replace("px", ""))
                    this.parentHeight = (windowHeight)? windowHeight : parentHeight;
                    var parentHeightInt = this.parentHeight - 0;
                    this.windowHeight = windowHeight;

                    // Get the window shade dimension
                    var lytWindowShade = this.getDescendantOfName("lytWindowShade", false, false) ;
                    var lytWindowShadeDimensionArray = lytWindowShade.getDimensionArray();

                    // set the distance to scroll

                    var temp = 0 - parentHeightInt;

                    // var temp = lytWindowShadeDimensionArray[1] - parentHeightInt;


                    this.setDistance(Math.abs(temp));

                    // Initialize the window shade top
                    var tempTop = 0
                    if (intDirection == 1)
                        tempTop = 0 - parentHeightInt;

                    this.setTop(tempTop, false)

                    this.setHeight(parentHeightInt, false);

                    this.rendered = this.getRendered()
                    if (this.rendered) {
                        this.rendered.style.top = tempTop
                    }


                    this.fragment = Math.round(((this.getDistance() * this.getTimeout()) / this.getDuration()) - 0.5);

                    this._calcScrollEndPoint(this.getDirection());

                }
                catch(e)
                {
                    windowshade.LOGGER.error("Error setting parameters:\n" + e.description + "\n" + e);
                }
            }


            windowshade.prototype._scrollWindowVertical = function(fragment, endpoint, currentTop) {
                var newTop = currentTop + fragment;
                this.rendered.style.top = newTop
                //tibco.admin.util.Log.SYSTEM.trace(" newTop = " + newTop + " this.direction " + this.direction + "  endpoint " + endpoint)
                if (this.direction * newTop < endpoint) {
                    var me = this
                    setTimeout(function() {
                        me._scrollWindowVertical(fragment, endpoint, newTop)
                    }, this.timeout);
                }
                else {
                    this._switchDirection();
                    this.initializeParameters(this.getDirection(), this.getTimeout(), this.getDuration(), this.windowHeight)
                }
            }

            windowshade.prototype.scrollWindowVertical = function() {

                var fragment = this.fragment * this.direction
                var endpoint = this.direction * this.scrollEndpoint
                tibco.admin.util.Log.SYSTEM.trace("scrollWindowVertical fragment = " + fragment + " endpoint " + endpoint + " this.getTop() " + this.getTop())

                this.rendered = this.getRendered()
                this._scrollWindowVertical(fragment, endpoint, this.getTop());
            }

            windowshade.prototype.stagedClose = function () {
                jsx3.log("in stagedClose")
                if (this.direction == -1) {
                    this.scrollWindowVertical();

                }
                else {
                    this.scrollStaged()
                }

            }

            windowshade.prototype.stagedOpen = function () {
                if (this.predirection == 1) {
                    this.scrollStaged()
                }

            }


            windowshade.prototype.scrollStaged = function () {
                this.rendered = this.getRendered()
                var curenttop = this.getAbsolutePosition().T

                curenttop = parseInt(this.rendered.style.top.replace("px", ""))
                var endpoint = (this.predirection * 38) + curenttop 
                jsx3.log("endpoint " + endpoint +" curenttop " + curenttop)
                this._scrollStaged(8, endpoint, curenttop);
            }

            windowshade.prototype._scrollStaged = function(fragment, endpoint, currentTop) {
                jsx3.log("endpoint " + endpoint)
                var newTop = currentTop + (fragment * this.predirection);
                this.rendered.style.top = newTop
                if (this.predirection * newTop < this.predirection * endpoint) {
                    var me = this
                    setTimeout(function() {
                        me._scrollStaged(fragment, endpoint, newTop)
                    }, this.timeout);
                }
                else {
                    this.predirection = this.predirection * -1
                }
            }

            windowshade.prototype._calcScrollEndPoint = function (intDirection) {
                this.scrollEndpoint = this.getTop() + (intDirection * this.getDistance());
            }

            windowshade.prototype._switchDirection = function() {
                this.setDirection(this.getDirection() * -1)
            }

            windowshade.prototype.setErrorSummary = function(text) {

                this.getDescendantOfName("lblErrorSummary_1000").setText(text, true)
            }

            windowshade.prototype.isOpen = function() {
                return (this.predirection == -1)?true:flase;
            }


        }
        )